package org.ss.psci.util;

import java.util.ArrayList;
import java.util.List;

import org.ss.psci.entity.PmBid;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class JsonUtil {

	public static String listBeanToJson(List list) {
		List temp = new ArrayList();
		if (temp != null) {
			for (int i = 0; i < list.size(); i++) {
				JSONObject jsonObject = JSONObject.fromObject(list.get(i));
				temp.add(jsonObject.toString());
			}
		}
		String item = JSONArray.fromObject(temp).toString();
		item = item.replaceAll("\"", "'");
		return "rootData:"+item;
	}

	public static void main(String[] a) {
		List temp = new ArrayList();
		for (int i = 0; i < 2; i++) {
			PmBid bid = new PmBid();
			bid.setProjectName("pn" + i);
			bid.setAddress("add" + i);
			bid.setCompany("com" + i);
			temp.add(bid);
		}
		System.out.println(listBeanToJson(temp));
	}
}
